<extend name="layout/main" />

<block name="HEADER">
	<style type="text/css">
		.layui-layer-page .layui-layer-content{
			overflow: initial;
		}
		#grid .layui-table-view .layui-table td .layui-table-cell{
			height: 36px;
		    line-height: 36px;
		}
		#grid .layui-btn+.layui-btn {
		    margin-left: 0;
		}
	</style>
</block>

<block name="CONTENT">
	<div class="wrapper">
		<div class="panel-heading">
			<control:search id="searchs" />
		</div>
		<div class="content">
			<control:grid id="grid" padding="0" height="100%" />
		</div>
	</div>
</block>

<block name="FOOTER">
	<script type="text/javascript">
		var page = (function(ns){
     
		    //页面初始化
		    ns.init=function(){
		        ns.query();
		    }
		    
		    //搜索事件
		    ns.query=function(){
		    	grid.load( searchs.getData() );
		    }
		    
		    //新增
		    ns.add=function(){
		    	var filter = {
		            url: $.getModule('edit'),
		            oid:"",
		            mode:1
		        }
		        $.openIframe(filter, "新增",['750px', '580px']);
		    }
		    
		    //编辑
		    ns.edit=function(){
		    	var selectedRow = grid.getSelectedRows()[0];
		        var filter = {
		            url:$.getModule('edit'),
		            oid: selectedRow.id ,
		            mode:2
		        }
		        $.openIframe(filter, "编辑",['750px', '580px']);
		    }  
		    
		    //删除
		    ns.del =function(){
		    	var selectedRows = grid.getSelectedRows();
		    	if(!selectedRows[0]){
		    		return $.toast(0,'请选择数据！');
		    	}
		    	var names = $.map(selectedRows, function(h) {
		    		return h.name;
		    	}).join(',');
		    	var ids = $.map(selectedRows, function(h) {
		    		return h.id;
		    	}).join(',');
		    	$.confirm("删除活动【"+names+"】，确认删除？",function(index){
		    		layer.close(index);
    				grid.updateField(ids,'is_del',1);
    			});
		    	//grid.deleteSelectRow(true);
		    }
		    
		    //下拉移动  type: 1 = 上移 ,  type: 2 = 下移
		    ns.move = function(type){
		    	grid.adjustSort(type,"sort_no");
		    }
		    
		    //启用禁用
		    ns.setEnable =function(state){
		    	var selectedRow = grid.getSelectedRows()[0];
		    	if(!selectedRow){
		    		return $.toast(0,'请选择数据！');
		    	}
		    	grid.updateField(grid.getSelectedColumnValue("id"),'is_enable',''+state);
		    }
		    
		 	//启用禁用
		    ns.setShare =function(id,state){
		    	grid.updateField(id,'is_share',''+state);
		    }
		    
		    //打开地推明细
		    ns.openDetailed =function(state){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		        var filter = {
		            url: $.getModule('detailed'),
		            oid: grid.getSelectedColumnValue("id"),
		            name: grid.getSelectedColumnValue("name"),
		            spread_id: grid.getSelectedColumnValue("spread_id"),
		            mode:2
		        }
		        $.openIframe(filter, "明细",['870px', '520px']);
		    }
		    
		    //查看范围
			ns.seeRanges = function(latitude,longitude,ranges){
				var filter = {
		            url: $.getModule('edit_selectLat'),
		            latitude: latitude,
		            longitude: longitude,
		            circle: ranges
		        }
		        $.openIframe(filter, "查看范围",['600px', '550px']);
			}
			
			//活动地址
			ns.activityAddress = function(id){
				$.ajaxs("/admin/v1/lottery/getUrl",{id:id}).then(function(res){
			    	layer.prompt({
			            title:"活动地址",
			            formType: 2,
			            offset: '20%',
			            value:res.data,
			            btn:['复制','关闭'],
			            success:function(layero){
			            	$(layero).find('.layui-layer-input').prop("disabled",true);
			            },
			            yes: function(index, layero,value){
			            	$(layero).find('.layui-layer-input').prop("disabled",false);
			            	$(layero).find('.layui-layer-input').select(); 
			            	document.execCommand("Copy");
			            	$(layero).find('.layui-layer-input').prop("disabled",true);
		                    $.toast(1,"复制成功！");
		                }
			        });
		        });
			}
			
		    return ns;
		}({}));
		
		$(function(){ page.init();  });
	</script>
</block>